﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Diagnostics;
using System.Runtime.InteropServices;

using Styx;
using Styx.Helpers;
using Styx.Logic;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals;

namespace Healz
{
    public static class Utils
    {
        // Detect KeyState.
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true,
            CallingConvention = CallingConvention.Winapi)]
        public static extern short GetKeyState(int keyCode);


        public static Color LogColour = Color.Cyan;
        public static string PreText = "[SwInY - Healz] ";

        public static void Write(string Value, params object[] args)
        {
            Value = string.Format(Value, args);

            Logging.Write(LogColour, PreText + Value);
            Logging.WriteDebug(LogColour, PreText + Value);
            WriteToWoW(Value);
        }


        public static void WriteToWoW(string Value, params object[] args)
        {
            // if we dont want this dont do it
            if (!Healz.cSettings.WoWLog) return;

            Value = string.Format(Value, args);

            Lua.DoString("print(\"|cFFFF7D0A{0}|cFFFFFFFF {1} \");", PreText, Value);
        }

        public static void WriteDebug(string Value, params object[] args)
        {
            Value = string.Format(Value, args);

            Logging.WriteDebug(LogColour, PreText + Value);
        }

        public static void WriteCast(string SpellName)
        {
            Utils.Write("Casting {0}", SpellName);
        }

        public static void WriteCast(string SpellName, WoWPlayer Player)
        {
            Utils.Write("Casting {0} on '{1}'  [{2}%]", SpellName, Player.Name, (int)Player.HealthPercent);
        }

        public static void WriteCast(string SpellName, WoWPlayer Player, int Stacks)
        {
            Utils.Write("Casting {0} on '{1}' - [{2}/3]", SpellName, Player.Name, Stacks);
        }



        public static bool IsBotEnabled
        {
            get
            {
                bool isCapsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0;
                return isCapsLock;
            }
        }
    }
}
